package primenumber;

import java.util.Scanner;

import songuyenlon.SoNguyenLon;

public class CheckPrimeNumber{
	
	final static SoNguyenLon Hai = new SoNguyenLon("2");
	final static SoNguyenLon Mot = new SoNguyenLon("1");
	final static SoNguyenLon Khong = new SoNguyenLon("0");
	
	/*
	 *  Uoc luong gia tri can cua so nguyen co so chu so lon hon 2
	 */
	
	private static SoNguyenLon Can(SoNguyenLon A) {
	       int m = A.Dodai();
	        if(m%2 == 0){
	            m = (m-2)/2;
	            int n = m/9 +1;
	            int[] ma = new int[n];
	            ma[0] = (int) (6*Math.pow(10, m%9));
	            return new SoNguyenLon(ma,n);
		}
		else{
	            m = m/2;
	            int n = m/9 +1;
	            int[] ma = new int[n];
	            ma[0] = (int) (2*Math.pow(10, m%9));
	            return new SoNguyenLon(ma,n);
		}
	}
	
	/*
	 * Kiem tra SoNguyenLon A co phai la so nguyen to hay khong
	 * Neu dung tra ve: true
	 * Neu sai tra ve: false
	 */
	
	private static boolean CheckPrimeNumber(SoNguyenLon A){
        SoNguyenLon B = Hai;
        boolean kiemtra = true;
        SoNguyenLon A1 = new SoNguyenLon();
        if(A.Sosanh(new SoNguyenLon("10")) == -1)
            A1 = A.Tru(Mot);
        else 
            A1 = Can(A);
        while(B.Sosanh(A1) <= 0){
            if(A.Phandu(B).Sosanh(Khong) == 0){
                return kiemtra = false;
            }
            B = B.Cong(Mot);
        }
        return kiemtra;
    }
	
	/*
	 * Ham main()
	 */
	
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
        System.out.print("Kiem tra so: ");
        String m = s.next();
        long start,stop;
        start = System.currentTimeMillis();
        System.out.println("Co phai la so nguyen to: "+CheckPrimeNumber(new SoNguyenLon(m)));
        stop = System.currentTimeMillis();
        System.out.println("Thoi gian chay = "+(stop-start));
    }
	
}
